package com.xqls.service.impl;

import com.xqls.bean.MessageBean;
import com.xqls.dal.dao.MessageDao;
import com.xqls.dal.model.Message;
import com.xqls.service.MessageService;
import com.xqls.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class MessageServiceImpl implements MessageService{

	@Autowired private MessageDao dao;
    @Value("${message.url}")
    private  String  messageUrl ;
    @Value("${message.applicationID}")
    private  String applicationID ;
    @Value("${message.password}")
    private String password ;
    @Value("${message.extendCode}")
    private String extendCode ;
	
	@Override
	public boolean add(MessageBean bean){
		return dao.insert((Message)ObjectUtil.transfer(bean, Message.class));
	}
	
	@Override
	public MessageBean queryByKey(Integer key){
		return (MessageBean) ObjectUtil.transfer(dao.selectByKey(key), MessageBean.class);
	}
	
	@Override
	public List<Map<String, Object>> queryByMap(Map<String, Object> map){
		return dao.selectByMap(map);
	}


	public boolean sendMessage(String phones ,String message,int alarmType) throws Exception{
    //    Sms sms = new Sms(messageUrl);
        String gateWayid;
        //发送短信
      //  gateWayid = sms.SendMessage(phones, message, extendCode, applicationID,password);
        MessageBean messageBean=new MessageBean();
        messageBean.setAlarmType(alarmType);
        messageBean.setMessageContent(message);
        messageBean.setPhoneNumber(phones);
        messageBean.setSendTime(new Date());
   //     messageBean.setReserved2(gateWayid);
        return  add(messageBean);
    }







}
